<template>
  <div style="height: 100%">
  </div>
</template>

<script>
  import EchartsMixins from '../echarts.mixins'
  import Format from '@/utils/format'
  var Echarts = require('echarts')

  export default {
    mixins: [EchartsMixins],
    data() {
      return {
        yAxisList: [],
        charts: '',
        xAngleList: [],
        compensateXAngleList: [],
        // 监测点名称
        monitorName: '',
        seriesLists: [],
      }
    },
    computed: {
      options() {
        const that = this
        return {
          title: {
            text: this.monitorName + '振动变化曲线图',
            x: 'center',
            align: 'center',
          },
          grid: {
            left: '7%',
            right: '8%',
            bottom: '70px'
          },
          // 图例组件
          legend: {
            data:  ['xg','yg','zg'],
            y: 'top',
            x: 'right',
            padding: [60, 5, 0, 0],
            // 设置为可滚动的图例
            type: 'scroll',
            orient: 'vertical'
          },
          toolbox: {
            right: '5',
            feature: {
              dataZoom: {
                yAxisIndex: 'none'
              },
              restore: {},
              saveAsImage: {}
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'line',

              label: {
                backgroundColor: '#505765'
              }
            },
            formatter: (params, ticket, callback) => {
              var contentArr = []
              contentArr.push(Format(new Date(params[0].value[0])))
              for (var i = 0; i < params.length; i++) {
                var data = params[i]
                contentArr.push(data.marker + data.seriesName + '值：' + data.value[1] + 'g')

              }
              let remark = params[0]?.data?.remark || ''
              remark && contentArr.push(`<p style='font-size:10px;' >${this.sliceStr(remark)}</p>`)
              return contentArr.join('<br/>')
            },
          },
          dataZoom: [
            {
              show: true,
              realtime: true,
              handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
              handleSize: '80%',
              handleStyle: {
                color: '#fff',
                shadowBlur: 3,
                shadowColor: 'rgba(0, 0, 0, 0.6)',
                shadowOffsetX: 2,
                shadowOffsetY: 2
              }
            },
            {
              type: 'inside',
              realtime: true
            }
          ],
          xAxis: {
            splitLine: {
              show: false
            },
            type: 'time',
            symbol: 'none',
            boundaryGap: false,
            axisLabel: { // 坐标轴标签样式设置
              formatter: function (value, index) { // 坐标轴文字展示样式处理
                return Echarts.format.formatTime('yyyy-MM-dd', new Date(value))
              },
            }
          },
          yAxis: {
            max: function (value) {
              return Math.ceil(value.max);//向上取整
            },
            name: '振动(g)',
            type: 'value'
          },

          series: this.seriesLists
        }
      }
    },
    methods: {
      updateEchart(data, monitorName,) {
        this.dataLists=data
        this.charts.clear()
        this.monitorName = monitorName
        this.seriesLists = [{
          yAxisIndex: 0,
          name: 'xg',
          type: 'line',
          smooth: false,
          // symbol: 'none',
          splitNumber: 1,
          data: data.xg,
        },{
          yAxisIndex: 0,
          name: 'yg',
          type: 'line',
          smooth: false,
          splitNumber: 1,
          data: data.yg,
        },
          ,{
            yAxisIndex: 0,
            name: 'zg',
            type: 'line',
            smooth: false,
            splitNumber: 1,
            data: data.zg,
          },
        ]
        this.initEcharts()
        this.charts.setOption(this.options)
        this.charts.resize()
      },
    },

  }
</script>
